package com.art.sunflower.mapper;

import com.art.sunflower.enumeration.RoleType;
import com.art.sunflower.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {

    @Select("select * from user where username = #{username}")
    User selectUser(String username);

    @Insert("insert into user(username, password, role, real_name, phone) values(#{username}, #{password}, #{role}, #{realName}, #{phone})")
    void insertUser(User user);

    @Update("update user set password = #{password} where username = #{username}")
    void updatePassword(String username, String password);

    @Update("update user set real_name = #{realName} where username = #{username}")
    void updateRealName(String username, String realName);

    @Insert("insert into user(username, password, role, real_name, phone) values(#{username}, #{password}, #{role}, #{name}, #{phone})")
    void insertUserAll(String username, String password, RoleType role, String name, String phone);

    @Select("select last_insert_id()")
    Integer selectLastInsertId();

    @Update("update user set username = #{username}, password = #{password}, real_name = #{name}, phone = #{phone} where id = #{id}")
    void updateUser(Integer id, String username, String password, String name, String phone);

    @Select("select * from user where id = #{id}")
    User selectUserById(Integer id);

    @Delete("delete from user where id = #{id}")
    void delete(Integer id);

    @Select("select * from user")
    List<User> selectAll();

    @Insert("insert into user(username, password, role, real_name, phone) values(#{username}, #{password}, #{role}, #{realName}, #{phone})")
    int insertUser1(User user);

}
